//
//  Segmentor.cpp
//  iosjieba
//
//  Created by yanyiwu on 14/12/24.
//  Copyright (c) 2014年 yanyiwu. All rights reserved.
//

#include "Segmentor.h"
#include <iostream>
#include <sys/timeb.h>
using namespace cppjieba;

cppjieba::MixSegment * globalSegmentor;
cppjieba::FullSegment *fullSegmentor;
cppjieba::Jieba * jieba;

void JiebaInit(const string& dictPath, const string& hmmPath, const string& userDictPath)
{
    if(globalSegmentor == NULL) {
        globalSegmentor = new MixSegment(dictPath, hmmPath, userDictPath);
    }
    
    cout << __FILE__ << __LINE__ << endl;
}

void JiebaCut(const string& sentence, vector<string>& words)
{
    long long start = systemtime();
    assert(globalSegmentor);
    globalSegmentor->Cut(sentence, words);
    cout << __FILE__ << __LINE__ << endl;
    cout << words << endl;
    
    cout<<systemtime()-start<<" 毫秒";
}

void JieBaInit(const string& dictPath, const string& hmmPath, const string& userDictPath, const string& idfPath, const string& stopWordsPath) 
{
    if (jieba == NULL) {
        jieba = new Jieba(dictPath, hmmPath, userDictPath, idfPath, stopWordsPath);
        
    }
    cout << __FILE__ << __LINE__ << endl;
}
void JiebaCutOrigin(const string& sentence, vector<string>& words)
{
    long long start = systemtime();
    assert(jieba);
    jieba->Cut(sentence, words);
    //cout << __FILE__ << __LINE__ << endl;
    cout << words << endl;
    
    cout<<systemtime()-start<<" 毫秒";
}

long long systemtime()
{
    timeb t;
    ftime(&t);
    return t.time*1000+t.millitm;
}
